import { defineStore } from 'pinia';
import { dataList } from './listData';
import { saveConfig } from '@/api/templates/templates';
import { configData } from '@/api/templates/templates';
import { MessagePlugin } from 'tdesign-vue-next';
import { settemplateListStyle, getComputeIndex, HistoryListType } from '@/utils/setmaterialStyle';
import _, { drop } from 'lodash';
import { getPreview, previewUpdate } from '@/api/project/project';
import { GetfreeData, SavefreeData } from '@/api/templates/templates';
import { disassociate, moduleSave, moduleDelete } from '@/api/desgin/desgin';
import { bindFreeShowpieces } from '@/api/exhibit/exhibit';
import { psthOutline } from '@/utils/minxin';
import { setBrowse } from '@/api/borwse/borwse';
import {
  getRemConversion,
  getExhibitsHeight,
  addExhibitsItemPosition,
  getFallbackType,
  collisionDetection,
  setcollisionArr,
  groupPostionCalculate,
  getMOdeListArr,
  getMOdeListcorrelation,
  ExportInfoType,
} from '@/utils/getRemComputed';
import {
  SetfreeDataStyle,
  filterFreeData,
  CancatExhibitList,
  exportActiveExhibitListInfo,
  AddXNumberExhibitList,
} from '@/material/index';
// @ts-nocheck
interface LogsType {
  id: number;
  userName: String;
  refType: number;
  refId: number;
  refName: String;
}
interface MembersType {
  isOneself: Boolean;
  phone: String;
  company: String;
  email: String;
  auditStatus: number;
  name: String;
}
interface projectData {
  coverUrl: String;
  createDate: String;
  isAsterisk: Boolean;
  name: String;
  description: String;
  createUserName: String;
  projectId: number | String;
  publishStatus: number;
  role: number;
  logs: Array<LogsType>;
  members: Array<MembersType>;
}
interface StyleInfo {
  background: String;
}
export const useProjectStore = defineStore('project', {
  state: () => ({
    previewMode: 1,
    previewModuleIndex: 0,
    previewModeShow:false,
    isUploadRadio: false,
    audioPlayType: false,
    audioPlaying: false,
    audioPlayUrl: '',
    audioPlayId: 0,
    audioPlayUserType: 1,
    progressVisible: false, //进度条显示
    previewId: 0, //预览id
    isActivitys: false, //是否是活动
    replaceSceneShow: false, //背景更换弹框
    audioDom: null, //音频
    isAudioPlay: false, //是否播放
    isMobileType: true, ///true是否是移动端
    id: 0, //党纲编辑器使用id
    bannerShow: false, //首页滑动
    bannerLock: false, //首页页面锁
    homeScrollLeft: 0, //当前滚动距离
    editExhibitId: 0, //当前编辑的展品id 0则为新增
    resizeShow: true, //屏幕刷新状态
    unitDleteShow: false, //删除单元或辅助信息弹框
    selectAuxiliaryIndex: -1, //设置辅助信息index
    materialType: 0, //更换素材类型1 2 3 123级大纲 4 辅助 5 展品类型
    addExbitionShow: false, //添加展品弹框
    projectRole: 3,
    heartbeatCurrent: 0, //页面心跳值
    modelIndex: false, //辅助信息弹框层级
    auxiliaryId: 0, //辅助信息id
    auxiliaryvisible: false, //辅助信息弹框
    auxiliaryTitleType: 1, //辅助信息弹框类型（新增/编辑/查看）
    auxiliaryType: false, //更新状态
    templateType: 0,
    delId: 0,
    tabvalue: 0,
    AddUnitstatus: false,
    planChildType: false,
    moveStarX: 0,
    moveStarWidth: 0,
    modeId: 0,
    moveAuxiliaryShow: false, //辅助信息弹框
    draggableShowcaseShow: false,
    exhibitsInfoShow: false, //展品详情弹框
    exhibitsShowpieceid: 0, //展品详情id
    videoInfoShow: false, //视频弹框
    videoInfoUrl: {}, //视频链接
    exhibitsModuleId: 0, //展品详情分组id
    replaceMaterialsShow: false, //更换样式弹框
    HistoryList: -1, //历史记录列表
    recoveryList: [], //总记录列表
    contextmenuchildId: 0, //右键选择的大纲id
    contextmenuGroupId: -1, //右键选中的大纲分组id
    contextmenuExhibitId: 0, //右键选中的展品id
    loginModeShow: false, //登录弹框显示
    auxiliaryShow: false, //辅助信息编辑弹框
    materialsReplaceShow: false, //素材更换弹框
    addGroupExhibitsShow: false, //添加分组展品弹框
    addGroupExhibitsShowSelectId: 0, //添加分组展品弹框选择类型
    addGroupExhibitsShowName: '', //添加分组展品弹框选择类型
    delExbitShow: false, //删除展品弹框
    delGroupShow: false, //删除展品分组弹框
    OutlineSortShow: false, //编辑大纲结构
    AuxiliarySrotShow: false, //辅助信息弹框
    unitEditShow: false, //编辑单元信息
    sortExbitionShow: false, ////调整展品顺序弹框
    sortShow: false, //排序调整
    childRemarks: '', //单元描述
    childTitle: '', //单元标题
    childRemarksShow: false, //单元描述弹框
    CustomDialogShow: false, //定制内容弹框
    childSubTitle: '', //单元副标题
    childIndex: 0, //单元下标
    style11Audio: new Audio(),
    menuId: null,
    styleInfo: {
      logo: '',
      moduleList: [],
      id: 0, //模板id
      projectId: 0, //模板id
      styleType: 1, //风格样式
      banners: [], //首页轮播图
      wapBanners: [], //移动端轮播图
      backgroundImage: null,
    },
    itemList: {
      type: 1,
      number: 6,
      showpieceTotal: 8,
      subTitle: '',
      isAuxiliary: false,
      auxiliaryTotal: 4,
      children: [],
      id: 505056006086725,
      parentId: 0,
      text: '',
      value: '',
      remarks: '',
      sort: 10,
      level: 1,
      width: null,
      showpieceList: [],
    },
    templateMOdeList: [], //dataList
    updateType: false,
  }),
  getters: {},
  actions: {
    async getPreviewId(projectId: number | string) {
      let res = await getPreview(projectId);
      this.previewId = res.data.id;
      console.log(this.previewId, '预览id');
    },
    async updatePreviewId(projectId: number | string) {
      let res = await previewUpdate(projectId);
      if (res.succeeded) {
        this.previewId = res.data.id;
        MessagePlugin.success('刷新成功');
      }
      // console.log(res, '刷新预览id');
    },
    SetpreviewModeShow(){
      this.previewModeShow=true
      setTimeout(() => { 
        this.previewModeShow=false
      }, 1890);
    },
    audioDomOperateStop() {
      this.audioDom.pause();
      this.audioPlayUrl = ''
    },
    setAudioPlayType() {
      this.audioPlayType = !this.audioPlayType
      if (this.audioPlayType) {
        if (this.audioPlayUrl && this.audioDom && this.audioDom.scr == this.audioPlayUrl) {
          this.audioDom.play()
          // this.audioPlaying = true
        } else {
          this.audioDomOperate()
        }
      } else {
        if (this.audioDom) {
          this.audioDom.pause();
          this.audioPlaying = false
        }

      }
    },
    audioDomOperate(src: string) {
      // audioPlayUrl
      if (this.audioDom) {
        // audioDom.remove();
        // this.audioDom = document.createElement('audio');

      } else {
        this.audioDom = document.createElement('audio');
        this.audioDom.addEventListener('play', function () {
          console.log('音频播放开始');
          this.audioPlaying = true;
          // 这里可以添加音频播放结束后要执行的代码
        });
        this.audioDom.addEventListener('ended', function () {
          console.log('音频播放结束');
          this.audioPlaying = false
          // 这里可以添加音频播放结束后要执行的代码
        });
      }
      if (this.audioPlayType) {
        this.audioDom.pause();
        this.audioDom.src = this.audioPlayUrl;
        this.audioDom.play();
      } else {

        // this.audioDom.src = this.audioPlayUrl;

      }


    },
    audioDomPlay(src: string) {
      this.audioDom = document.createElement('audio');
      if (this.audioDom.paused) {
        this.audioDom.src = src;
        this.audioDom.pause();
        this.audioDom.currentTime = 0; // 重置播放位置
        // 如果暂停，则播放音频，并更新按钮文本
        this.audioDom.play();
        this.isAudioPlay = true;
      } else {
        // 如果正在播放，则暂停音频，并更新按钮文本
        this.audioDom.pause();
        this.isAudioPlay = false;
      }
    },
    initType() {
      const isMobile = navigator.userAgent.match(
        /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i,
      );

      if (isMobile) {
        this.isMobileType = true;
      } else {
        this.isMobileType = false;
      }

      this.loginModeShow = false;
      this.materialsReplaceShow = false;
      this.replaceSceneShow = false;
      this.OutlineSortShow = false;
      this.unitEditShow = false;
      this.childRemarksShow = false;
      this.CustomDialogShow = false;
      this.replaceMaterialsShow = false;
      this.addGroupExhibitsShow = false;
      this.moveAuxiliaryShow = false;
      this.addGroupExhibitsShowSelectId = 0;
      this.addGroupExhibitsShowName = '';
      this.addExbitionShow = false;
      this.auxiliaryShow = false;
      this.exhibitsInfoShow = false;
      this.videoInfoShow = false;
      this.videoInfoUrl = {};
      this.AuxiliarySrotShow = false;
      this.LoginShow = false;
      this.unitDleteShow = false;
      this.delExbitShow = false;
      this.delGroupShow = false;
      this.resizeShow = true;
      this.sortExbitionShow = false;
      this.HistoryList = 0;
      this.homeScrollLeft = 0;
      this.recoveryList = [];
      this.bannerShow = false;
      this.bannerLock = false;
      this.progressVisible = false; 
      this.audioPlayType = false; 
      this.audioPlaying = false;
      this.audioDom = null;
      this.audioPlayUrl = null;
      this.audioPlayId = 0;
      this.isUploadRadio = false;
      this.previewMode = 1;
      this.previewModuleIndex = 0;
      this.previewModeShow=false;
      setBrowse({
        refType: 3,
        refId: localStorage.getItem('projectId'),
      });
    },
    setprogressVisible() {
      console.log('触发')
      this.progressVisible = !this.progressVisible
    },
    setstyleInfo(data: any, isReset?: boolean) {
      this.styleInfo.logo = data.logo;
      this.styleInfo.moduleList = data.moduleList;
      this.styleInfo.id = data.id;
      this.styleInfo.projectId = data.projectId;
      this.styleInfo.themeColor = data.themeColor ? data.themeColor : '#CFBDA8';
      this.styleInfo.auxiliaryColor = data.auxiliaryColor ? data.auxiliaryColor : '#F0E9E1';
      this.styleInfo.background = data.background ? data.background : '#FAF9F7';
      this.styleInfo.shmentColor = data.shmentColor ? data.shmentColor : '#D2AD77';
      this.styleInfo.fontColor = data.fontColor ? data.fontColor : '#333';
      this.styleInfo.fontFamily = data.fontFamily ? data.fontFamily : 'SourceHanSerifCN';
      this.styleInfo.textFamily = data.textFamily ? data.textFamily : 'SourceHanSerifCN';
      this.styleInfo.sizeType = data.sizeType ? data.sizeType : 1;
      if (isReset) {
        this.styleInfo.backgroundImage = null;
      }
      this.styleInfo.styleType = data.styleType ? data.styleType : 1;
      this.styleInfo.wapBanners = data.wapBanners;
      if (data.banners) {
        this.styleInfo.banners = [];
        data.banners.forEach((element) => {
          if (element.url) {
            this.styleInfo.banners.push(element);
          }
        });
      } else {
        this.styleInfo.banners = [];
      }
      // this.styleInfo.banners = data.banners ? data.banners : [];
      this.styleInfo.colorType = data.colorType ? data.colorType : 1;
      // console.log('moduleList', this.styleInfo.moduleList);
    },
    getStyleInfo() {
      configData(localStorage.getItem('projectId')).then((res) => {
        this.styleInfo = res.data;
      });
    },
    setStyleInfoBackground(url?: string) {
      this.styleInfo.backgroundImage = url ? url : null;
      MessagePlugin.success(url ? '设置成功' : '重置成功');
      saveConfig(localStorage.getItem('projectId'), this.styleInfo);
    },

    async getFreeInfoData(psth?: number) {
      //获取自由模式参数
      setTimeout(async () => {
        let { data } = await GetfreeData(localStorage.getItem('projectId')); //localStorage.getItem('projectId'));

        //     GetfreeData
        this.draggableShowcaseShow = false;
        let list = SetfreeDataStyle(data);
        this.templateMOdeList = list;
        this.draggableShowcaseShow = true;

        this.settingHistoryList();
        if (psth) {
          setTimeout(() => {
            psthOutline('Level1outline' + psth);
          }, 400);
        }
      }, 400);
      // console.log(this.templateMOdeList, '自由模式参数');
    },
    SaveFreeInfoData(e?: number) {
      //保存自由模式参数
      let newLiist = filterFreeData(this.templateMOdeList);
      SavefreeData(localStorage.getItem('projectId'), newLiist).then((res) => { });
      if (e) {
        this.getFreeInfoData();
      }
      this.settingHistoryList();
    },
    setItemHidden(e, index) {
      this.templateMOdeList[index].isShow = e;
    },
    setaddExbitionShow(e: boolean) {
      //添加录入弹框
      this.addExbitionShow = e;
    },
    setBanner(data: any) {
      this.styleInfo.banners = data;
    },
    setLogo(e) {
      //设置logo
      this.styleInfo.logo = e;
    },
    setAuxiliaryvisible(e: boolean) {
      //
      this.auxiliaryvisible = e;
    },
    setreplaceMaterialsShow(e: boolean) {
      //调整素材弹框
      this.replaceMaterialsShow = e;
    },
    setModelIndex(e: boolean) {
      this.modelIndex = e;
    },
    setAuxiliaryId(e: number) {
      this.auxiliaryId = e;
    },
    setAuxiliaryType() {
      this.auxiliaryType = !this.auxiliaryType;
    },
    setAuxiliaryTitleType(e: number) {
      this.auxiliaryTitleType = e;
    },
    settemplate9ScrollType(e: boolean) {
      this.template9ScrollType = e;
    },
    initTemplateList() {
      settemplateListStyle(this.templateMOdeList);
    },
    setTeplateType(data: number) {
      this.templateType = data;
    },
    setProjectRole(data: number) {
      this.projectRole = data;
    },
    settingHistoryList() {
      let clonedObject = _.cloneDeep(this.templateMOdeList);
      if (this.recoveryList.length === 0) {
        return;
      }
      this.recoveryList.forEach((element) => {
        element = clonedObject; //HistoryListType(indexList,type,element);//设置历史记录中变更的type
      });
    },

    setHistoryListItem() {
      let clonedObject = _.cloneDeep(this.templateMOdeList);
      this.recoveryList = [clonedObject];
      // if (this.recoveryList.lenngth < 10) {
      //   this.recoveryList.push(clonedObject);
      // } else {
      //   this.recoveryList.push(clonedObject);
      //   this.recoveryList.splice(0, 0);
      // }
      // this.HistoryList = this.HistoryList + 1 < 10 ? this.HistoryList + 1 : 9;
      // this.recoveryList.splice(this.HistoryList.length - 1, 0, clonedObject);
      // console.log(this.HistoryList);
    },
    fallbackAction() {
      this.templateMOdeList = this.recoveryList[0];

      this.updateType = !this.updateType;
      this.SaveFreeInfoData();
    },
    recovery() {
      // console.log(this.HistoryList,this.recoveryList[this.HistoryList])
      // if (!this.recoveryList[this.HistoryList + 1]) {
      //   return;
      // }
      // this.HistoryList = this.HistoryList + 1;
      // this.templateMOdeList = this.recoveryList[this.HistoryList];
      // console.log('触发恢复');
    },
    setOutlineSortShow(e: boolean) {
      this.OutlineSortShow = e;
    },
    setRemark(remark: string | null, title: string, subTitle?: string | null) {
      this.childRemarks = remark;
      this.childTitle = title;
      this.childSubTitle = subTitle ? subTitle : '';
    },
    setChildRemarksShow(e: boolean) {
      this.childRemarksShow = e;
    },
    setCustomDialogShow(e: boolean, index?: number) {
      this.CustomDialogShow = e;
      this.childIndex = index;
    },
    setSortShow(e: boolean) {
      this.sortShow = e;
    },
    setloginModeShow(e: boolean) {
      this.loginModeShow = e;
    },
    setMaterialsReplaceShow(e: boolean) {
      this.materialsReplaceShow = e;
    },
    setauxiliaryShow(e: boolean) {
      //辅助信息编辑弹框
      this.auxiliaryShow = e;
    },
    // this.auxiliaryShow=false
    setaddGroupExhibitsShow(e: boolean, type?: number) {
      //添加展品弹框
      this.addGroupExhibitsShow = e;
      this.addGroupExhibitsShowSelectId = type ? type : 0;
      if (type) {
        switch (type) {
          case 3:
            this.addGroupExhibitsShowName = '从本展览展品库选择展品';
            break;
          case 2:
            this.addGroupExhibitsShowName = '从私有库选择展品';
            break;
          case 1:
            this.addGroupExhibitsShowName = '从公有库选择展品';
            break;
          case 5:
            this.addGroupExhibitsShowName = '从我的关注选择展品';
            break;
        }
      }
    },

    setTemplateMOdeList(obj: any) {
      this.templateMOdeList = obj;
    },
    setItemList(AuxiliaryIndex?: number) {
      //获取大纲数据
      this.templateMOdeList.forEach((element) => {
        if (element.id == this.contextmenuchildId) {
          if (AuxiliaryIndex || AuxiliaryIndex === 0) {
            this.itemList = element.auxiliaryList[AuxiliaryIndex];
          } else {
            this.itemList = element;
          }
        }
        element.children.forEach((el) => {
          if (el.id == this.contextmenuchildId) {
            if (AuxiliaryIndex || AuxiliaryIndex === 0) {
              this.itemList = el.auxiliaryList[AuxiliaryIndex];
            } else {
              this.itemList = el;
            }
          }
          el.children.forEach((arr) => {
            if (arr.id == this.contextmenuchildId) {
              if (AuxiliaryIndex || AuxiliaryIndex === 0) {
                this.itemList = arr.auxiliaryList[AuxiliaryIndex];
              } else {
                this.itemList = arr;
              }
            }
          });
        });
      });
    },
    async sbmitItem(info: any) {
      //修改大纲数据
      let clonedObject = _.cloneDeep(info); //克隆传递过来的数据
      clonedObject.name = clonedObject.text;
      let idList = getMOdeListArr(this.templateMOdeList, this.contextmenuchildId);

      if (idList.length === 1) {
        this.templateMOdeList[idList[0]].digitalShowroom = info.digitalShowroom;
        this.templateMOdeList[idList[0]].text = info.text;
        this.templateMOdeList[idList[0]].value = info.value;
        this.templateMOdeList[idList[0]].subTitle = info.subTitle;
        this.templateMOdeList[idList[0]].remarks = info.description;
        clonedObject.id = this.templateMOdeList[idList[0]].id;
      } else if (idList.length === 2) {
        this.templateMOdeList[idList[0]].children[idList[1]].digitalShowroom = info.digitalShowroom;
        this.templateMOdeList[idList[0]].children[idList[1]].text = info.text;
        this.templateMOdeList[idList[0]].children[idList[1]].value = info.value;
        this.templateMOdeList[idList[0]].children[idList[1]].subTitle = info.subTitle;
        this.templateMOdeList[idList[0]].children[idList[1]].remarks = info.description;
        clonedObject.id = this.templateMOdeList[idList[0]].children[idList[1]].id;
      } else if (idList.length === 3) {
        this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].digitalShowroom = info.digitalShowroom;
        this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].text = info.text;
        this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].value = info.value;
        this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].subTitle = info.subTitle;
        this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].remarks = info.description;
        clonedObject.id = this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].id;
      }
      let res = await moduleSave(localStorage.getItem('projectId'), clonedObject);
    },
    sbmitAuxiliaryItem(info: any) {
      //修改大纲数据
      let idList = getMOdeListArr(this.templateMOdeList, this.contextmenuchildId);

      if (idList.length === 1) {
        this.templateMOdeList[idList[0]].auxiliaryList[this.selectAuxiliaryIndex].text = info.name;
        this.templateMOdeList[idList[0]].auxiliaryList[this.selectAuxiliaryIndex].value = info.coverUrl;
        this.templateMOdeList[idList[0]].auxiliaryList[this.selectAuxiliaryIndex].subTitle = info.subTitle;
        this.templateMOdeList[idList[0]].auxiliaryList[this.selectAuxiliaryIndex].remarks = info.description;
        this.templateMOdeList[idList[0]].auxiliaryList[this.selectAuxiliaryIndex].audio = info.audio;
        this.templateMOdeList[idList[0]].auxiliaryList[this.selectAuxiliaryIndex].video = info.video;
        this.templateMOdeList[idList[0]].auxiliaryList[this.selectAuxiliaryIndex].coverUrl = info.coverUrl;
      } else if (idList.length === 2) {
        this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[this.selectAuxiliaryIndex].text = info.name;
        this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[this.selectAuxiliaryIndex].value =
          info.coverUrl;
        this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[this.selectAuxiliaryIndex].subTitle =
          info.subTitle;
        this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[this.selectAuxiliaryIndex].remarks =
          info.description;
        this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[this.selectAuxiliaryIndex].audio =
          info.audio;
        this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[this.selectAuxiliaryIndex].video =
          info.video;
        this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[this.selectAuxiliaryIndex].coverUrl =
          info.coverUrl;
      } else if (idList.length === 3) {
        this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
          this.selectAuxiliaryIndex
        ].text = info.name;
        this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
          this.selectAuxiliaryIndex
        ].value = info.coverUrl;
        this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
          this.selectAuxiliaryIndex
        ].subTitle = info.subTitle;
        this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
          this.selectAuxiliaryIndex
        ].remarks = info.description;
        this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
          this.selectAuxiliaryIndex
        ].audio = info.audio;
        this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
          this.selectAuxiliaryIndex
        ].video = info.video;
        this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
          this.selectAuxiliaryIndex
        ].coverUrl = info.coverUrl;
      }
    },
    setExhibitsWidth(level1Id: number, widths: number, AuxiliaryId: number) {
      //设置当前展品列表的最大宽高
      this.templateMOdeList.forEach((element) => {
        if (element.id == level1Id) {
          if (AuxiliaryId !== -1) {
            element.auxiliaryList[AuxiliaryId].width = widths;
          } else {
            element.width = widths;
          }
        }
        element.children.forEach((el) => {
          if (el.id == level1Id) {
            if (AuxiliaryId !== -1) {
              el.auxiliaryList[AuxiliaryId].width = widths;
            } else {
              el.width = widths;
            }
          }
          el.children.forEach((arr) => {
            if (arr.id == level1Id) {
              if (AuxiliaryId !== -1) {
                arr.auxiliaryList[AuxiliaryId].width = widths;
                // console.log(AuxiliaryId,element.auxiliaryList[AuxiliaryId],'hahahahahahahahahah ')
                // el.auxiliaryList[AuxiliaryId] ? (el.auxiliaryList[AuxiliaryId].width = widths) : false;
              } else {
                arr.width = widths;
              }
            }
          });
        });
      });
      // setTimeout(() => {
      //   let newLiist = filterFreeData(this.templateMOdeList);
      //   // SavefreeData(localStorage.getItem('projectId'), newLiist).then((res) => { });
      // }, 800);
    },
    setStartX(level1Id: number, indexs: number, AuxiliaryId: any) {
      //设置初始点位
      setTimeout(() => {
        let idList = getMOdeListArr(this.templateMOdeList, level1Id);
        if (AuxiliaryId == -1) {
          if (idList.length === 1) {
            this.moveStarX = this.templateMOdeList[idList[0]].showpieceList[indexs].x;
            this.moveStarWidth = this.templateMOdeList[idList[0]].showpieceList[indexs].width;
          } else if (idList.length === 2) {
            this.moveStarX = this.templateMOdeList[idList[0]].children[idList[1]].showpieceList[indexs].x;
            this.moveStarWidth = this.templateMOdeList[idList[0]].children[idList[1]].showpieceList[indexs].width;
          } else if (idList.length === 3) {
            this.moveStarX =
              this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].showpieceList[indexs].x;
            this.moveStarWidth =
              this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].showpieceList[indexs].width;
          }
        } else {
          if (idList.length === 1) {
            this.moveStarX = this.templateMOdeList[idList[0]].auxiliaryList[AuxiliaryId].showpieceList[indexs].x;
            this.moveStarWidth =
              this.templateMOdeList[idList[0]].auxiliaryList[AuxiliaryId].showpieceList[indexs].width;
          } else if (idList.length === 2) {
            this.moveStarX =
              this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[AuxiliaryId].showpieceList[indexs].x;
            this.moveStarWidth =
              this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[AuxiliaryId].showpieceList[
                indexs
              ].width;
          } else if (idList.length === 3) {
            this.moveStarX =
              this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
                AuxiliaryId
              ].showpieceList[indexs].x;
            this.moveStarWidth =
              this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
                AuxiliaryId
              ].showpieceList[indexs].width;
          }
        }
      }, 0);
    },
    setExhibitsItemWidth(level1Id: number, indexs: number, info: any, end: string | boolean, AuxiliaryId: number) {
      //设置当前展品距离相对父元素的xy偏移量
      // console.log('碰撞', end);
      // if (!info.x || !info.y) {
      //   return;
      // }
      setTimeout(() => {
        if (info.x < 0 && end) {
          this.fallbackAction();
        }
        let moveX = 0;
        this.templateMOdeList.forEach((element) => {
          if (element.id == level1Id) {
            // [ListIndex]
            if (AuxiliaryId !== -1) {
              moveX = element.auxiliaryList[AuxiliaryId].showpieceList[indexs].x - info.x;
              element.auxiliaryList[AuxiliaryId].showpieceList[indexs].x = getRemConversion(info.x);
              if (element.auxiliaryList[AuxiliaryId].showpieceList[indexs].x < 0 && end) {
                element.auxiliaryList[AuxiliaryId].showpieceList[indexs].x = 0;
              }
              element.auxiliaryList[AuxiliaryId].showpieceList[indexs].y = getExhibitsHeight(info.y);
              let metathesis = getComputeIndex(
                element.auxiliaryList[AuxiliaryId].showpieceList,
                info,
                this.moveStarX,
                this.moveStarWidth,
                indexs,
              ); //换位下标
              if (metathesis.collisionIndex !== -1) {
                let newX = element.auxiliaryList[AuxiliaryId].showpieceList[metathesis.collisionIndex].x;
                if (metathesis.position === 1) {
                  element.auxiliaryList[AuxiliaryId].showpieceList[metathesis.collisionIndex].x =
                    this.moveStarX +
                    this.moveStarWidth -
                    element.auxiliaryList[AuxiliaryId].showpieceList[metathesis.collisionIndex].width;
                } else {
                  element.auxiliaryList[AuxiliaryId].showpieceList[metathesis.collisionIndex].x = this.moveStarX;
                }
                this.moveStarX = newX;
              }
            } else {
              moveX = element.showpieceList[indexs].x - info.x;
              element.showpieceList[indexs].x = getRemConversion(info.x);
              if (element.showpieceList[indexs].x < 0 && end) {
                element.showpieceList[indexs].x = 0;
              }
              element.showpieceList[indexs].y = getExhibitsHeight(info.y);
              let metathesis = getComputeIndex(element.showpieceList, info, this.moveStarX, this.moveStarWidth, indexs); //换位下标
              if (metathesis.collisionIndex !== -1) {
                let newX = element.showpieceList[metathesis.collisionIndex].x;
                if (metathesis.position === 1) {
                  element.showpieceList[metathesis.collisionIndex].x =
                    this.moveStarX + this.moveStarWidth - element.showpieceList[metathesis.collisionIndex].width;
                } else {
                  element.showpieceList[metathesis.collisionIndex].x = this.moveStarX;
                }
                this.moveStarX = newX;
              }
            }
          }
          element.children.forEach((el) => {
            if (el.id == level1Id) {
              if (AuxiliaryId !== -1) {
                moveX = el.auxiliaryList[AuxiliaryId].showpieceList[indexs].x - info.x;
                el.auxiliaryList[AuxiliaryId].showpieceList[indexs].x = getRemConversion(info.x);
                if (el.auxiliaryList[AuxiliaryId].showpieceList[indexs].x < 0 && end) {
                  el.auxiliaryList[AuxiliaryId].showpieceList[indexs].x = 0;
                }
                el.auxiliaryList[AuxiliaryId].showpieceList[indexs].y = getExhibitsHeight(info.y);
                let metathesis = getComputeIndex(
                  el.auxiliaryList[AuxiliaryId].showpieceList,
                  info,
                  this.moveStarX,
                  this.moveStarWidth,
                  indexs,
                ); //换位下标
                if (metathesis.collisionIndex !== -1) {
                  let newX = el.auxiliaryList[AuxiliaryId].showpieceList[metathesis.collisionIndex].x;
                  if (metathesis.position === 1) {
                    el.auxiliaryList[AuxiliaryId].showpieceList[metathesis.collisionIndex].x =
                      this.moveStarX +
                      this.moveStarWidth -
                      el.auxiliaryList[AuxiliaryId].showpieceList[metathesis.collisionIndex].width;
                  } else {
                    el.auxiliaryList[AuxiliaryId].showpieceList[metathesis.collisionIndex].x = this.moveStarX;
                  }
                  this.moveStarX = newX;
                }
              } else {
                moveX = el.showpieceList[indexs].x - info.x;
                el.showpieceList[indexs].x = getRemConversion(info.x);
                if (el.showpieceList[indexs].x < 0 && end) {
                  el.showpieceList[indexs].x = 0;
                }
                el.showpieceList[indexs].y = getExhibitsHeight(info.y);
                let metathesis = getComputeIndex(el.showpieceList, info, this.moveStarX, this.moveStarWidth, indexs); //换位下标
                if (metathesis.collisionIndex !== -1) {
                  let newX = el.showpieceList[metathesis.collisionIndex].x;
                  if (metathesis.position === 1) {
                    el.showpieceList[metathesis.collisionIndex].x =
                      this.moveStarX + this.moveStarWidth - el.showpieceList[metathesis.collisionIndex].width;
                  } else {
                    el.showpieceList[metathesis.collisionIndex].x = this.moveStarX;
                  }
                  this.moveStarX = newX;
                }
              }
            }
            el.children.forEach((arr) => {
              if (arr.id == level1Id) {
                if (AuxiliaryId !== -1) {
                  moveX = arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].x - info.x;
                  arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].x = getRemConversion(info.x);
                  if (arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].x < 0 && end) {
                    arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].x = 0;
                  }
                  arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].y = getExhibitsHeight(info.y);
                  let metathesis = getComputeIndex(
                    arr.auxiliaryList[AuxiliaryId].showpieceList,
                    info,
                    this.moveStarX,
                    this.moveStarWidth,
                    indexs,
                  ); //换位下标
                  if (metathesis.collisionIndex !== -1) {
                    let newX = arr.auxiliaryList[AuxiliaryId].showpieceList[metathesis.collisionIndex].x;
                    if (metathesis.position === 1) {
                      arr.auxiliaryList[AuxiliaryId].showpieceList[metathesis.collisionIndex].x =
                        this.moveStarX +
                        this.moveStarWidth -
                        arr.auxiliaryList[AuxiliaryId].showpieceList[metathesis.collisionIndex].width;
                    } else {
                      arr.auxiliaryList[AuxiliaryId].showpieceList[metathesis.collisionIndex].x = this.moveStarX;
                    }
                    this.moveStarX = newX;
                  }
                } else {
                  moveX = arr.showpieceList[indexs].x - info.x;
                  arr.showpieceList[indexs].x = getRemConversion(info.x);
                  if (arr.showpieceList[indexs].x < 0 && end) {
                    arr.showpieceList[indexs].x = 0;
                  }
                  arr.showpieceList[indexs].y = getExhibitsHeight(info.y);
                  let metathesis = getComputeIndex(arr.showpieceList, info, this.moveStarX, this.moveStarWidth, indexs); //换位下标
                  if (metathesis.collisionIndex !== -1) {
                    let newX = arr.showpieceList[metathesis.collisionIndex].x;
                    if (metathesis.position === 1) {
                      arr.showpieceList[metathesis.collisionIndex].x =
                        this.moveStarX + this.moveStarWidth - arr.showpieceList[metathesis.collisionIndex].width;
                    } else {
                      arr.showpieceList[metathesis.collisionIndex].x = this.moveStarX;
                    }
                    this.moveStarX = newX;
                  }
                }
              }
            });
          });
        });

        if (end) {
          this.collisionSeeting(level1Id, indexs, AuxiliaryId);
          if (end && info.x < 0) {
            // this.updateType = !this.updateType;
          }
        }
      }, 0);
    },

    setExhibitsItemImgWidth(level1Id: number, indexs: number, info: any, AuxiliaryId: number) {
      //设置当前展品图片距离相对父元素的xy偏移量

      if (!info.x || !info.y) {
        return;
      }
      this.templateMOdeList.forEach((element) => {
        if (element.id == level1Id) {
          if (AuxiliaryId !== -1) {
            element.auxiliaryList[AuxiliaryId].showpieceList[indexs].imgX = getRemConversion(info.x);
            element.auxiliaryList[AuxiliaryId].showpieceList[indexs].imgH = getExhibitsHeight(info.y);
          } else {
            element.showpieceList[indexs].imgX = getRemConversion(info.x);
            element.showpieceList[indexs].imgH = getExhibitsHeight(info.y);
          }
        }
        element.children.forEach((el) => {
          if (el.id == level1Id) {
            if (AuxiliaryId !== -1) {
              el.auxiliaryList[AuxiliaryId].showpieceList[indexs].imgX = getRemConversion(info.x);
              el.auxiliaryList[AuxiliaryId].showpieceList[indexs].imgH = getExhibitsHeight(info.y);
            } else {
              el.showpieceList[indexs].imgX = getRemConversion(info.x);
              el.showpieceList[indexs].imgH = getExhibitsHeight(info.y);
            }
          }
          el.children.forEach((arr) => {
            if (arr.id == level1Id) {
              if (AuxiliaryId !== -1) {
                arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].imgX = getRemConversion(info.x);
                arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].imgH = getExhibitsHeight(info.y);
              } else {
                arr.showpieceList[indexs].imgX = getRemConversion(info.x);
                arr.showpieceList[indexs].imgH = getExhibitsHeight(info.y);
              }
            }
          });
        });
      });
    },
    setExhibitsGroupWidth(level1Id: number, indexs: number, info: any, ListIndex: number, AuxiliaryId: number) {
      //设置当前分组展品图片距离相对父元素的xy偏移量

      setTimeout(() => {
        if (!info.x || !info.y) {
          return;
        }
        this.templateMOdeList.forEach((element) => {
          if (element.id == level1Id) {
            if (AuxiliaryId !== -1) {
              element.auxiliaryList[AuxiliaryId].showpieceList[indexs].showpieceList[ListIndex].x = getRemConversion(
                info.x,
              );
              element.auxiliaryList[AuxiliaryId].showpieceList[indexs].showpieceList[ListIndex].y = getExhibitsHeight(
                info.y,
              );
            } else {
              element.showpieceList[indexs].showpieceList[ListIndex].x = getRemConversion(info.x);
              element.showpieceList[indexs].showpieceList[ListIndex].y = getExhibitsHeight(info.y);
            }
          }
          element.children.forEach((el) => {
            if (el.id == level1Id) {
              if (AuxiliaryId !== -1) {
                el.auxiliaryList[AuxiliaryId].showpieceList[indexs].showpieceList[ListIndex].x = getRemConversion(
                  info.x,
                );
                el.auxiliaryList[AuxiliaryId].showpieceList[indexs].showpieceList[ListIndex].y = getExhibitsHeight(
                  info.y,
                );
              } else {
                el.showpieceList[indexs].showpieceList[ListIndex].x = getRemConversion(info.x);
                el.showpieceList[indexs].showpieceList[ListIndex].y = getExhibitsHeight(info.y);
              }
            }
            el.children.forEach((arr) => {
              if (arr.id == level1Id) {
                if (AuxiliaryId !== -1) {
                  arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].showpieceList[ListIndex].x = getRemConversion(
                    info.x,
                  );
                  arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].showpieceList[ListIndex].y = getExhibitsHeight(
                    info.y,
                  );
                } else {
                  arr.showpieceList[indexs].showpieceList[ListIndex].x = getRemConversion(info.x);
                  arr.showpieceList[indexs].showpieceList[ListIndex].y = getExhibitsHeight(info.y);
                }
              }
            });
          });
        });
      }, 0);
    },
    collisionSeeting(level1Id: number, indexs: number, AuxiliaryId: number) {
      //判断是否碰撞方法
      setTimeout(() => {
        let activeNumber = 0;
        let collisionNUmber: number = 0;
        this.templateMOdeList.forEach((element, elementIndex) => {
          if (element.id === level1Id) {
            if (AuxiliaryId !== -1) {
              collisionNUmber = collisionDetection(
                element.auxiliaryList[AuxiliaryId].showpieceList,
                element.auxiliaryList[AuxiliaryId].showpieceList[indexs].width,
                element.auxiliaryList[AuxiliaryId].showpieceList[indexs].x,
                indexs,
              );
              console.log('碰撞', collisionNUmber);
              if (collisionNUmber !== 0) {
                if (collisionNUmber < 0) {
                  let setItems = setcollisionArr(element.auxiliaryList[AuxiliaryId], collisionNUmber, indexs);
                  this.templateMOdeList[elementIndex].auxiliaryList[AuxiliaryId] = setItems;
                  this.updateType = !this.updateType;
                } else {
                  this.fallbackAction();
                }
              } else {
                return;
              }
            } else {
              collisionNUmber = collisionDetection(
                element.showpieceList,
                element.showpieceList[indexs].width,
                element.showpieceList[indexs].x,
                indexs,
              );

              if (collisionNUmber !== 0) {
                if (collisionNUmber < 0) {
                  let setItems = setcollisionArr(element, collisionNUmber, indexs);
                  this.templateMOdeList[elementIndex] = setItems;
                  this.updateType = !this.updateType;
                } else {
                  this.fallbackAction();
                }
              } else {
                return;
              }
            }
          }

          element.children.forEach((el, elIndex) => {
            if (el.id === level1Id) {
              if (AuxiliaryId !== -1) {
                collisionNUmber = collisionDetection(
                  el.auxiliaryList[AuxiliaryId].showpieceList,
                  el.auxiliaryList[AuxiliaryId].showpieceList[indexs].width,
                  el.auxiliaryList[AuxiliaryId].showpieceList[indexs].x,
                  indexs,
                );
                // console.log('碰撞', collisionNUmber);
                if (collisionNUmber !== 0) {
                  if (collisionNUmber < 0) {
                    let setItems = setcollisionArr(el.auxiliaryList[AuxiliaryId], collisionNUmber, indexs);
                    this.templateMOdeList[elementIndex].children[elIndex].auxiliaryList[AuxiliaryId] = setItems;
                    this.updateType = !this.updateType;
                  } else {
                    this.fallbackAction();
                  }
                } else {
                  return;
                }
              } else {
                collisionNUmber = collisionDetection(
                  el.showpieceList,
                  el.showpieceList[indexs].width,
                  el.showpieceList[indexs].x,
                  indexs,
                );
                if (collisionNUmber !== 0) {
                  if (collisionNUmber < 0) {
                    let setItems = setcollisionArr(el, collisionNUmber, indexs);
                    this.templateMOdeList[elementIndex].children[elIndex] = setItems;
                    this.updateType = !this.updateType;
                  } else {
                    this.fallbackAction();
                  }
                } else {
                  return;
                }
              }
            }
            el.children.forEach((arr, arrIndex) => {
              if (arr.id === level1Id) {
                if (AuxiliaryId !== -1) {
                  collisionNUmber = collisionDetection(
                    arr.auxiliaryList[AuxiliaryId].showpieceList,
                    arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].width,
                    arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].x,
                    indexs,
                  );

                  if (collisionNUmber !== 0) {
                    if (collisionNUmber < 0) {
                      let setItems = setcollisionArr(arr.auxiliaryList[AuxiliaryId], collisionNUmber, indexs);
                      this.templateMOdeList[elementIndex].children[elIndex].children[arrIndex].auxiliaryList[
                        AuxiliaryId
                      ] = setItems;
                      this.updateType = !this.updateType;
                    } else {
                      this.fallbackAction();
                    }
                  } else {
                    return;
                  }
                } else {
                  collisionNUmber = collisionDetection(
                    arr.showpieceList,
                    arr.showpieceList[indexs].width,
                    arr.showpieceList[indexs].x,
                    indexs,
                  );
                  console.log('碰撞', collisionNUmber);
                  if (collisionNUmber !== 0) {
                    // this.fallbackAction();
                    if (collisionNUmber < 0) {
                      let setItems = setcollisionArr(arr, collisionNUmber, indexs);
                      this.templateMOdeList[elementIndex].children[elIndex].children[arrIndex] = setItems;
                      //                     elementIndex
                      // elIndex
                      this.updateType = !this.updateType;
                    } else {
                      this.fallbackAction();
                    }
                  } else {
                    return;
                  }
                }
              }
            });
          });
        });
      }, 0);
    },
    setExhibitsItemStyle(level1Id: number, indexs: number, info: any, end: string, AuxiliaryId: number) {
      // this.setHistoryListItem()
      //设置当前展品距离相对父元素的宽高
      let newArr: any;
      this.templateMOdeList.forEach((element) => {
        if (element.id == level1Id) {
          if (AuxiliaryId !== -1) {
            element.auxiliaryList[AuxiliaryId].showpieceList[indexs].width = getRemConversion(info.w);
            element.auxiliaryList[AuxiliaryId].showpieceList[indexs].showcaseWidth =
              element.auxiliaryList[AuxiliaryId].showpieceList[indexs].width - 0.2;
            // disabledW
            element.auxiliaryList[AuxiliaryId].showpieceList[indexs].height = getExhibitsHeight(info.h);
            if (end) {
              newArr = groupPostionCalculate(element.auxiliaryList[AuxiliaryId].showpieceList[indexs]);
              element.auxiliaryList[AuxiliaryId].showpieceList[indexs] = { ...newArr };
            }
          } else {
            element.showpieceList[indexs].width = getRemConversion(info.w);
            element.showpieceList[indexs].showcaseWidth = element.showpieceList[indexs].width - 0.2;
            // disabledW
            element.showpieceList[indexs].height = getExhibitsHeight(info.h);
            if (end) {
              newArr = groupPostionCalculate(element.showpieceList[indexs]);
              element.showpieceList[indexs] = { ...newArr };
            }
          }
        }
        element.children.forEach((el) => {
          if (el.id == level1Id) {
            if (AuxiliaryId !== -1) {
              el.auxiliaryList[AuxiliaryId].showpieceList[indexs].width = getRemConversion(info.w);
              el.auxiliaryList[AuxiliaryId].showpieceList[indexs].showcaseWidth =
                el.auxiliaryList[AuxiliaryId].showpieceList[indexs].width - 0.2;
              el.auxiliaryList[AuxiliaryId].showpieceList[indexs].height = getExhibitsHeight(info.h);
              if (end) {
                newArr = groupPostionCalculate(el.auxiliaryList[AuxiliaryId].showpieceList[indexs]);
                el.auxiliaryList[AuxiliaryId].showpieceList[indexs] = { ...newArr };
              }
            } else {
              el.showpieceList[indexs].width = getRemConversion(info.w);
              el.showpieceList[indexs].height = getExhibitsHeight(info.h);
              el.showpieceList[indexs].showcaseWidth = el.showpieceList[indexs].width - 0.2;
              if (end) {
                newArr = groupPostionCalculate(el.showpieceList[indexs]);
                el.showpieceList[indexs] = { ...newArr };
              }
            }
          }
          el.children.forEach((arr) => {
            if (arr.id == level1Id) {
              if (AuxiliaryId !== -1) {
                arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].width = getRemConversion(info.w);
                arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].showcaseWidth =
                  arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].width - 0.2;
                arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].height = getExhibitsHeight(info.h);
                if (end) {
                  newArr = groupPostionCalculate(arr.auxiliaryList[AuxiliaryId].showpieceList[indexs]);
                  arr.auxiliaryList[AuxiliaryId].showpieceList[indexs] = { ...newArr };
                }
              } else {
                arr.showpieceList[indexs].width = getRemConversion(info.w);
                arr.showpieceList[indexs].height = getExhibitsHeight(info.h);
                arr.showpieceList[indexs].showcaseWidth = arr.showpieceList[indexs].width - 0.2;
                if (end) {
                  newArr = groupPostionCalculate(arr.showpieceList[indexs]);
                  arr.showpieceList[indexs] = { ...newArr };
                }
              }
            }
          });
        });
      });
      if (end) {
        // console.log('end')
        this.collisionSeeting(level1Id, indexs, AuxiliaryId);
        this.updateType = !this.updateType;
      }
    },

    setExhibitsItemImgStyle(level1Id: number, indexs: number, info: any, AuxiliaryId: number) {
      //设置当前展品图距离相对父元素的宽高
      // console.log(info);
      this.templateMOdeList.forEach((element) => {
        if (element.id == level1Id) {
          if (AuxiliaryId !== -1) {
            element.auxiliaryList[AuxiliaryId].showpieceList[indexs].imgWidth = getRemConversion(info.w);
            element.auxiliaryList[AuxiliaryId].showpieceList[indexs].imgHeight = getExhibitsHeight(info.h);
          } else {
            element.showpieceList[indexs].imgWidth = getRemConversion(info.w);
            element.showpieceList[indexs].imgHeight = getExhibitsHeight(info.h);
          }
        }
        element.children.forEach((el) => {
          if (el.id == level1Id) {
            if (AuxiliaryId !== -1) {
              el.auxiliaryList[AuxiliaryId].showpieceList[indexs].imgWidth = getRemConversion(info.w);
              el.auxiliaryList[AuxiliaryId].showpieceList[indexs].imgHeight = getExhibitsHeight(info.h);
            } else {
              el.showpieceList[indexs].imgWidth = getRemConversion(info.w);
              el.showpieceList[indexs].imgHeight = getExhibitsHeight(info.h);
            }
          }
          el.children.forEach((arr) => {
            if (arr.id == level1Id) {
              if (AuxiliaryId !== -1) {
                arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].imgWidth = getRemConversion(info.w);
                arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].imgHeight = getExhibitsHeight(info.h);
              } else {
                arr.showpieceList[indexs].imgWidth = getRemConversion(info.w);
                arr.showpieceList[indexs].imgHeight = getExhibitsHeight(info.h);
              }
            }
          });
        });
      });
    },
    setExhibitsGroupStyle(level1Id: number, indexs: number, info: any, ListIndex: number, AuxiliaryId: number) {
      //设置当前分组展品距离相对父元素的宽高
      // console.log(info);
      setTimeout(() => {
        this.templateMOdeList.forEach((element) => {
          if (element.id == level1Id) {
            if (AuxiliaryId !== -1) {
              element.auxiliaryList[AuxiliaryId].showpieceList[indexs].showpieceList[ListIndex].width =
                getRemConversion(info.w);
              element.auxiliaryList[AuxiliaryId].showpieceList[indexs].showpieceList[ListIndex].height =
                getExhibitsHeight(info.h);
            } else {
              element.showpieceList[indexs].showpieceList[ListIndex].width = getRemConversion(info.w);
              element.showpieceList[indexs].showpieceList[ListIndex].height = getExhibitsHeight(info.h);
            }
          }
          element.children.forEach((el) => {
            if (el.id == level1Id) {
              if (AuxiliaryId !== -1) {
                el.auxiliaryList[AuxiliaryId].showpieceList[indexs].showpieceList[ListIndex].width = getRemConversion(
                  info.w,
                );
                el.auxiliaryList[AuxiliaryId].showpieceList[indexs].showpieceList[ListIndex].height = getExhibitsHeight(
                  info.h,
                );
              } else {
                el.showpieceList[indexs].showpieceList[ListIndex].width = getRemConversion(info.w);
                el.showpieceList[indexs].showpieceList[ListIndex].height = getExhibitsHeight(info.h);
              }
            }
            el.children.forEach((arr) => {
              if (arr.id == level1Id) {
                if (AuxiliaryId !== -1) {
                  arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].showpieceList[ListIndex].width =
                    getRemConversion(info.w);
                  arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].showpieceList[ListIndex].height =
                    getExhibitsHeight(info.h);
                } else {
                  arr.showpieceList[indexs].showpieceList[ListIndex].width = getRemConversion(info.w);
                  arr.showpieceList[indexs].showpieceList[ListIndex].height = getExhibitsHeight(info.h);
                }
              }
            });
          });
        });
      }, 0);
    },

    //设置展柜属性
    setshowcaseWidth(level1Id: number, indexs: number, info: any, AuxiliaryId: number) {
      //设置当前展品距离相对父元素的xy偏移量

      if (!info.y) {
        return;
      }

      this.templateMOdeList.forEach((element) => {
        if (element.id == level1Id) {
          if (AuxiliaryId !== -1) {
            element.auxiliaryList[AuxiliaryId].showpieceList[indexs].showcaseX = getRemConversion(info.x);
            element.auxiliaryList[AuxiliaryId].showpieceList[indexs].showcaseY = getExhibitsHeight(info.y);
          } else {
            element.showpieceList[indexs].showcaseX = getRemConversion(info.x);
            element.showpieceList[indexs].showcaseY = getExhibitsHeight(info.y);
          }
          // [ListIndex]
        }
        element.children.forEach((el) => {
          if (el.id == level1Id) {
            if (AuxiliaryId !== -1) {
              el.auxiliaryList[AuxiliaryId].showpieceList[indexs].showcaseX = getRemConversion(info.x);
              el.auxiliaryList[AuxiliaryId].showpieceList[indexs].showcaseY = getExhibitsHeight(info.y);
            } else {
              el.showpieceList[indexs].showcaseX = getRemConversion(info.x);
              el.showpieceList[indexs].showcaseY = getExhibitsHeight(info.y);
            }
          }
          el.children.forEach((arr) => {
            if (arr.id == level1Id) {
              if (AuxiliaryId !== -1) {
                arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].showcaseX = getRemConversion(info.x);
                arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].showcaseY = getExhibitsHeight(info.y);
              } else {
                arr.showpieceList[indexs].showcaseX = getRemConversion(info.x);
                arr.showpieceList[indexs].showcaseY = getExhibitsHeight(info.y);
              }
            }
          });
        });
      });
    },
    setShowcaseStyle(level1Id: number, indexs: number, info: any, AuxiliaryId: number) {
      //设置当前展品距离相对父元素的宽高
      this.templateMOdeList.forEach((element) => {
        if (element.id == level1Id) {
          if (AuxiliaryId !== -1) {
            element.auxiliaryList[AuxiliaryId].showpieceList[indexs].showcaseHeight = getExhibitsHeight(info.h);
          } else {
            element.showpieceList[indexs].showcaseHeight = getExhibitsHeight(info.h);
          }
          // element.showpieceList[indexs].showcaseWidth = getRemConversion(info.w);
        }
        element.children.forEach((el) => {
          if (el.id == level1Id) {
            if (AuxiliaryId !== -1) {
              el.auxiliaryList[AuxiliaryId].showpieceList[indexs].showcaseHeight = getExhibitsHeight(info.h);
            } else {
              el.showpieceList[indexs].showcaseHeight = getExhibitsHeight(info.h);
            }
          }
          el.children.forEach((arr) => {
            if (arr.id == level1Id) {
              if (AuxiliaryId !== -1) {
                arr.auxiliaryList[AuxiliaryId].showpieceList[indexs].showcaseHeight = getExhibitsHeight(info.h);
              } else {
                arr.showpieceList[indexs].showcaseHeight = getExhibitsHeight(info.h);
              }
            }
          });
        });
      });
    },
    //右键分组追加一个展品
    addExhibitsItem(indexs?: number) {
      //设置当前展品距离相对父元素的宽高this.contextmenuGroupId
      setTimeout(() => {
        console.log(indexs);
        this.templateMOdeList.forEach((element) => {
          if (element.id == this.contextmenuchildId) {
            if (indexs > -1) {
              let PositionX = addExhibitsItemPosition(
                element.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].showpieceList,
              );
              element.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].showpieceList.push({
                x: PositionX,
                y: null,
                width: 1.1888,
                height: 22,
                imgWidth: 1.1888,
                imgHeight: 15,
                imgX: 0,
                imgH: 0,
              });

              element.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].width =
                element.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].width + 1.3888;
              element.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].showcaseWidth =
                element.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].showcaseWidth + 1.3888;
            } else {
              let PositionX = addExhibitsItemPosition(element.showpieceList[this.contextmenuGroupId].showpieceList);
              element.showpieceList[this.contextmenuGroupId].showpieceList.push({
                x: PositionX,
                y: null,
                width: 1.1888,
                height: 22,
                imgWidth: 1.1888,
                imgHeight: 15,
                imgX: 0,
                imgH: 0,
              });

              element.showpieceList[this.contextmenuGroupId].width =
                element.showpieceList[this.contextmenuGroupId].width + 1.3888;
              element.showpieceList[this.contextmenuGroupId].showcaseWidth =
                element.showpieceList[this.contextmenuGroupId].showcaseWidth + 1.3888;
            }
          }
          element.children.forEach((el) => {
            if (el.id == this.contextmenuchildId) {
              if (indexs > -1) {
                let PositionX = addExhibitsItemPosition(
                  el.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].showpieceList,
                );
                el.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].showpieceList.push({
                  x: PositionX,
                  y: null,
                  width: 1.1888,
                  height: 22,
                  imgWidth: 1.1888,
                  imgHeight: 15,
                  imgX: 0,
                  imgH: 0,
                });

                el.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].width =
                  el.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].width + 1.3888;
                el.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].showcaseWidth =
                  el.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].showcaseWidth + 1.3888;
              } else {
                let PositionX = addExhibitsItemPosition(el.showpieceList[this.contextmenuGroupId].showpieceList);
                el.showpieceList[this.contextmenuGroupId].showpieceList.push({
                  x: PositionX,
                  y: null,
                  width: 1.1888,
                  height: 22,
                  imgWidth: 1.1888,
                  imgHeight: 15,
                  imgX: 0,
                  imgH: 0,
                });
                el.showpieceList[this.contextmenuGroupId].width =
                  el.showpieceList[this.contextmenuGroupId].width + 1.3888;
                el.showpieceList[this.contextmenuGroupId].showcaseWidth =
                  el.showpieceList[this.contextmenuGroupId].showcaseWidth + 1.3888;
              }
            }
            el.children.forEach((arr) => {
              if (arr.id == this.contextmenuchildId) {
                if (indexs > -1) {
                  let PositionX = addExhibitsItemPosition(
                    arr.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].showpieceList,
                  );
                  arr.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].showpieceList.push({
                    x: PositionX,
                    y: null,
                    width: 1.1888,
                    height: 22,
                    imgWidth: 1.1888,
                    imgHeight: 15,
                    imgX: 0,
                    imgH: 0,
                  });

                  arr.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].width =
                    arr.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].width + 1.3888;
                  arr.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].showcaseWidth =
                    arr.auxiliaryList[indexs].showpieceList[this.contextmenuGroupId].showcaseWidth + 1.3888;
                } else {
                  let PositionX = addExhibitsItemPosition(arr.showpieceList[this.contextmenuGroupId].showpieceList);
                  arr.showpieceList[this.contextmenuGroupId].showpieceList.push({
                    x: PositionX,
                    y: null,
                    width: 1.1888,
                    height: 22,
                    imgWidth: 1.1888,
                    imgHeight: 15,
                    imgX: 0,
                    imgH: 0,
                  });
                  arr.showpieceList[this.contextmenuGroupId].width =
                    arr.showpieceList[this.contextmenuGroupId].width + 1.3888;
                  arr.showpieceList[this.contextmenuGroupId].showcaseWidth =
                    arr.showpieceList[this.contextmenuGroupId].showcaseWidth + 1.3888;
                }
              }
            });
          });
        });
        this.collisionSeeting(this.contextmenuchildId, this.contextmenuGroupId, indexs);
        this.updateType = !this.updateType;
      }, 0);
    },
    async removeExhibitGroupFn(id: number, list: any) {
      //移除指定展品分组
      try {
        let arr = [];
        if (this.contextmenuExhibitId == -1) {
          list.forEach((el) => {
            arr.push(el.id);
          });
        } else {
          arr = [list[this.contextmenuExhibitId].id];
        }
        console.log(arr);
        let res = await bindFreeShowpieces(localStorage.getItem('projectId'), id, arr);
        this.settingHistoryList();
      } catch (err) {
        console.log(err);
      }
    },
    removeExhibitsGroup(index?: number) {
      //删除指定展品分组活分组中的指定项
      if (index !== -1) {
        this.removeAuxiliaryExhibitsGroup(index);
        this.settingHistoryList();
        return;
      }
      setTimeout(() => {
        this.templateMOdeList.forEach((element) => {
          if (element.id == this.contextmenuchildId) {
            this.removeExhibitGroupFn(element.id, element.showpieceList[this.contextmenuGroupId].showpieceList);

            if (this.contextmenuExhibitId == -1) {
              //若果这个参数不等于-1的话 这断定是删除展品分组中的某个展品 否则的话便是整组删除
              element.showpieceList.forEach((elementChild) => {
                let delType = getFallbackType(elementChild.x, element.showpieceList[this.contextmenuGroupId].x);
                if (delType) {
                  elementChild.x = elementChild.x - element.showpieceList[this.contextmenuGroupId].width;
                }
              });

              element.showpieceList.splice(this.contextmenuGroupId, 1);
            } else {
              if (element.showpieceList[this.contextmenuGroupId].showpieceList.length === 1) {
                element.showpieceList.splice(this.contextmenuGroupId, 1);
              } else {
                element.showpieceList[this.contextmenuGroupId].showpieceList.splice(this.contextmenuExhibitId, 1);
              }
            }
          }
          element.children.forEach((el) => {
            if (el.id == this.contextmenuchildId) {
              this.removeExhibitGroupFn(el.id, el.showpieceList[this.contextmenuGroupId].showpieceList);
              if (this.contextmenuExhibitId == -1) {
                el.showpieceList.forEach((elChild) => {
                  let delType = getFallbackType(elChild.x, el.showpieceList[this.contextmenuGroupId].x);
                  if (delType && this.contextmenuExhibitId !== -1) {
                    elChild.x = elChild.x - el.showpieceList[this.contextmenuGroupId].width;
                  }
                });

                el.showpieceList.splice(this.contextmenuGroupId, 1);
              } else {
                if (el.showpieceList[this.contextmenuGroupId].showpieceList.length === 1) {
                  el.showpieceList.splice(this.contextmenuGroupId, 1);
                } else {
                  el.showpieceList[this.contextmenuGroupId].showpieceList.splice(this.contextmenuExhibitId, 1);
                }
              }
            }
            el.children.forEach((arr) => {
              if (arr.id == this.contextmenuchildId) {
                this.removeExhibitGroupFn(arr.id, arr.showpieceList[this.contextmenuGroupId].showpieceList);
                if (this.contextmenuExhibitId == -1) {
                  arr.showpieceList.forEach((arrChild) => {
                    let delType = getFallbackType(arrChild.x, arr.showpieceList[this.contextmenuGroupId].x);
                    if (delType && this.contextmenuExhibitId !== -1) {
                      arrChild.x = arrChild.x - arr.showpieceList[this.contextmenuGroupId].width;
                    }
                  });

                  arr.showpieceList.splice(this.contextmenuGroupId, 1);
                } else {
                  if (arr.showpieceList[this.contextmenuGroupId].showpieceList.length === 1) {
                    arr.showpieceList.splice(this.contextmenuGroupId, 1);
                  } else {
                    arr.showpieceList[this.contextmenuGroupId].showpieceList.splice(this.contextmenuExhibitId, 1);
                  }
                }
              }
            });
          });
        });
        this.settingHistoryList();

        this.getFreeInfoData();

        // this.SaveFreeInfoData();
        this.updateType = !this.updateType;
        MessagePlugin.success('删除成功');
      }, 6);
    },
    removeAuxiliaryExhibitsGroup(index: number) {
      //删除辅助信息指定展品分组活分组中的指定项

      setTimeout(() => {
        MessagePlugin.success('删除成功');
        this.templateMOdeList.forEach((element) => {
          if (element.id == this.contextmenuchildId) {
            console.log(element.auxiliaryList, index);
            this.removeExhibitGroupFn(
              element.auxiliaryList[index].id,
              element.auxiliaryList[index].showpieceList[this.contextmenuGroupId].showpieceList,
            );

            if (this.contextmenuExhibitId == -1) {
              //若果这个参数不等于-1的话 这断定是删除展品分组中的某个展品 否则的话便是整组删除
              element.auxiliaryList[index].showpieceList.forEach((elementChild) => {
                let delType = getFallbackType(
                  elementChild.x,
                  element.auxiliaryList[index].showpieceList[this.contextmenuGroupId].x,
                );
                if (delType) {
                  elementChild.x =
                    elementChild.x - element.auxiliaryList[index].showpieceList[this.contextmenuGroupId].width;
                }
              });
              element.auxiliaryList[index].showpieceList.splice(this.contextmenuGroupId, 1);
            } else {
              if (element.auxiliaryList[index].showpieceList[this.contextmenuGroupId].showpieceList.length === 1) {
                element.auxiliaryList[index].showpieceList.splice(this.contextmenuGroupId, 1);
              } else {
                element.auxiliaryList[index].showpieceList[this.contextmenuGroupId].showpieceList.splice(
                  this.contextmenuExhibitId,
                  1,
                );
              }
            }
          }
          element.children.forEach((el) => {
            if (el.id == this.contextmenuchildId) {
              this.removeExhibitGroupFn(
                el.auxiliaryList[index].id,
                el.auxiliaryList[index].showpieceList[this.contextmenuGroupId].showpieceList,
              );
              if (this.contextmenuExhibitId == -1) {
                el.auxiliaryList[index].showpieceList.forEach((elChild) => {
                  let delType = getFallbackType(elChild.x ? elChild.x : 0, el.showpieceList[this.contextmenuGroupId].x);
                  if (delType && this.contextmenuExhibitId !== -1) {
                    elChild.x = elChild.x - el.auxiliaryList[index].showpieceList[this.contextmenuGroupId].width;
                  }
                });

                el.auxiliaryList[index].showpieceList.splice(this.contextmenuGroupId, 1);
              } else {
                if (el.auxiliaryList[index].showpieceList[this.contextmenuGroupId].showpieceList.length === 1) {
                  el.auxiliaryList[index].showpieceList.splice(this.contextmenuGroupId, 1);
                } else {
                  el.auxiliaryList[index].showpieceList[this.contextmenuGroupId].showpieceList.splice(
                    this.contextmenuExhibitId,
                    1,
                  );
                }
              }
            }
            el.children.forEach((arr) => {
              if (arr.id == this.contextmenuchildId) {
                this.removeExhibitGroupFn(
                  arr.auxiliaryList[index].id,
                  arr.auxiliaryList[index].showpieceList[this.contextmenuGroupId].showpieceList,
                );
                if (this.contextmenuExhibitId == -1) {
                  arr.auxiliaryList[index].showpieceList.forEach((arrChild) => {
                    let delType = getFallbackType(arrChild.x, arr.showpieceList[this.contextmenuGroupId].x);
                    if (delType && this.contextmenuExhibitId !== -1) {
                      arrChild.x = arrChild.x - arr.auxiliaryList[index].showpieceList[this.contextmenuGroupId].width;
                    }
                  });

                  arr.auxiliaryList[index].showpieceList.splice(this.contextmenuGroupId, 1);
                } else {
                  if (arr.auxiliaryList[index].showpieceList[this.contextmenuGroupId].showpieceList.length === 1) {
                    arr.auxiliaryList[index].showpieceList.splice(this.contextmenuGroupId, 1);
                  } else {
                    arr.auxiliaryList[index].showpieceList[this.contextmenuGroupId].showpieceList.splice(
                      this.contextmenuExhibitId,
                      1,
                    );
                  }
                }
              }
            });
          });
        });
        // this.SaveFreeInfoData();
        this.settingHistoryList();

        this.getFreeInfoData();

        this.updateType = !this.updateType;
      }, 2);
    },
    removeExhibitsItem(level1Id?: number, indexs?: number) {
      //删除某个展品
      setTimeout(() => {
        this.templateMOdeList.forEach((element) => {
          if (element.id == this.contextmenuchildId) {
            if (element.showpieceList[this.contextmenuGroupId].showpieceList.length > 1) {
              element.showpieceList[this.contextmenuGroupId].showpieceList.splice(this.contextmenuExhibitId, 1);
            } else {
              element.showpieceList.forEach((elementChild) => {
                let delType = getFallbackType(elementChild.x, element.showpieceList[this.contextmenuGroupId].x);
                if (delType) {
                  elementChild.x = elementChild.x - element.showpieceList[this.contextmenuGroupId].width;
                }
              });
              element.showpieceList.splice(this.contextmenuGroupId, 1);
              this.updateType = !this.updateType;
            }
          }
          element.children.forEach((el) => {
            if (el.id == this.contextmenuchildId) {
              if (el.showpieceList[this.contextmenuGroupId].showpieceList.length > 1) {
                el.showpieceList[this.contextmenuGroupId].showpieceList.splice(this.contextmenuExhibitId, 1);
              } else {
                el.showpieceList.forEach((elChild) => {
                  let delType = getFallbackType(elChild.x, el.showpieceList[this.contextmenuGroupId].x);
                  if (delType) {
                    elChild.x = elChild.x - el.showpieceList[this.contextmenuGroupId].width;
                  }
                });
                el.showpieceList.splice(this.contextmenuGroupId, 1);
                this.updateType = !this.updateType;
              }
              // el.showpieceList[this.contextmenuGroupId].showpieceList.splice(this.contextmenuExhibitId, 1);
            }
            el.children.forEach((arr) => {
              if (arr.id == this.contextmenuchildId) {
                if (arr.showpieceList[this.contextmenuGroupId].showpieceList.length > 1) {
                  arr.showpieceList[this.contextmenuGroupId].showpieceList.splice(this.contextmenuExhibitId, 1);
                } else {
                  // arr.showpieceList.splice(this.contextmenuGroupId, 1); //[this.contextmenuGroupId].showpieceList.splice(this.contextmenuExhibitId, 1);
                  arr.showpieceList.forEach((arrChild) => {
                    let delType = getFallbackType(arrChild.x, arr.showpieceList[this.contextmenuGroupId].x);
                    if (delType) {
                      arrChild.x = arrChild.x - arr.showpieceList[this.contextmenuGroupId].width;
                    }
                  });
                  arr.showpieceList.splice(this.contextmenuGroupId, 1);
                  this.updateType = !this.updateType;
                }
                // arr.showpieceList[this.contextmenuGroupId].showpieceList.splice(this.contextmenuExhibitId, 1);
              }
            });
          });
        });
      }, 1);
    },
    addChildlistExhibit(indexList: Array<number>, idList: Array<number>) {
      //为大纲展品分组添加展品

      this.getFreeInfoData();
    },
    addChildlistExhibitGroup(idList: Array<number>, ExhibitList: Array<number>) {
      //为大纲展品分组添加展品
      setTimeout(() => {
        let maxAdd = 0; //添加后续长度
        // ExhibitionList
        let newArr = [];
        let cancatList = [];
        ExhibitList.forEach((el) => {
          let pushArr = {
            id: el,
            x: 0,
            y: 0,
            type: 0,
            width: 0,
            height: 0,
            imgWidth: 0,
            imgHeight: 0,
            imgX: 0,
            imgH: 0,
          };

          cancatList.push(pushArr);
        });

        try {
          // contextmenuGroupId
          if (idList.length === 1) {
            if (this.selectAuxiliaryIndex == -1) {
              newArr = CancatExhibitList(
                this.templateMOdeList[idList[0]].showpieceList[this.contextmenuGroupId].showpieceList,
                cancatList,
              );
              this.templateMOdeList[idList[0]].showpieceList[this.contextmenuGroupId].showpieceList = newArr;
              let ActiveInfo = exportActiveExhibitListInfo(
                this.templateMOdeList[idList[0]].showpieceList[this.contextmenuGroupId].type,
              );
              if (ActiveInfo.type !== 'cabinet') {
                this.templateMOdeList[idList[0]].showpieceList = AddXNumberExhibitList(
                  this.templateMOdeList[idList[0]].showpieceList,
                  this.contextmenuGroupId,
                  ActiveInfo.CoverWidth * cancatList.length,
                );
              }

              //  console.log(ActiveInfo,'当前选中的id');
            } else {
              newArr = CancatExhibitList(
                this.templateMOdeList[idList[0]].auxiliaryList[this.selectAuxiliaryIndex].showpieceList[
                  this.contextmenuGroupId
                ].showpieceList,
                cancatList,
              );
              this.templateMOdeList[idList[0]].auxiliaryList[this.selectAuxiliaryIndex].showpieceList[
                this.contextmenuGroupId
              ].showpieceList = newArr;
              let ActiveInfo = exportActiveExhibitListInfo(
                this.templateMOdeList[idList[0]].auxiliaryList[this.selectAuxiliaryIndex].showpieceList[
                  this.contextmenuGroupId
                ].type,
              );
              if (ActiveInfo.type !== 'cabinet') {
                this.templateMOdeList[idList[0]].auxiliaryList[this.selectAuxiliaryIndex].showpieceList =
                  AddXNumberExhibitList(
                    this.templateMOdeList[idList[0]].auxiliaryList[this.selectAuxiliaryIndex].showpieceList,
                    this.contextmenuGroupId,
                    ActiveInfo.CoverWidth * cancatList.length,
                  );
              }
            }
          } else if (idList.length === 2) {
            if (this.selectAuxiliaryIndex == -1) {
              newArr = CancatExhibitList(
                this.templateMOdeList[idList[0]].children[idList[1]].showpieceList[this.contextmenuGroupId]
                  .showpieceList,
                cancatList,
              );
              this.templateMOdeList[idList[0]].children[idList[1]].showpieceList[
                this.contextmenuGroupId
              ].showpieceList = newArr;
              let ActiveInfo = exportActiveExhibitListInfo(
                this.templateMOdeList[idList[0]].children[idList[1]].showpieceList[this.contextmenuGroupId].type,
              );
              if (ActiveInfo.type !== 'cabinet') {
                this.templateMOdeList[idList[0]].children[idList[1]].showpieceList = AddXNumberExhibitList(
                  this.templateMOdeList[idList[0]].children[idList[1]].showpieceList,
                  this.contextmenuGroupId,
                  ActiveInfo.CoverWidth * cancatList.length,
                );
              }
            } else {
              newArr = CancatExhibitList(
                this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[this.selectAuxiliaryIndex]
                  .showpieceList[this.contextmenuGroupId].showpieceList,
                cancatList,
              );
              this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[
                this.selectAuxiliaryIndex
              ].showpieceList[this.contextmenuGroupId].showpieceList = newArr;
              let ActiveInfo = exportActiveExhibitListInfo(
                this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[this.selectAuxiliaryIndex]
                  .showpieceList[this.contextmenuGroupId].type,
              );
              if (ActiveInfo.type !== 'cabinet') {
                this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[
                  this.selectAuxiliaryIndex
                ].showpieceList = AddXNumberExhibitList(
                  this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList[this.selectAuxiliaryIndex]
                    .showpieceList,
                  this.contextmenuGroupId,
                  ActiveInfo.CoverWidth * cancatList.length,
                );
              }
            }
          } else if (idList.length === 3) {
            if (this.selectAuxiliaryIndex == -1) {
              newArr = CancatExhibitList(
                this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].showpieceList[
                  this.contextmenuGroupId
                ].showpieceList,
                cancatList,
              );
              this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].showpieceList[
                this.contextmenuGroupId
              ].showpieceList = newArr;
              let ActiveInfo = exportActiveExhibitListInfo(
                this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].showpieceList[
                  this.contextmenuGroupId
                ].type,
              );
              if (ActiveInfo.type !== 'cabinet') {
                this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].showpieceList =
                  AddXNumberExhibitList(
                    this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].showpieceList,
                    this.contextmenuGroupId,
                    ActiveInfo.CoverWidth * cancatList.length,
                  );
              }
            } else {
              newArr = CancatExhibitList(
                this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
                  this.selectAuxiliaryIndex
                ].showpieceList[this.contextmenuGroupId].showpieceList,
                cancatList,
              );
              this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
                this.selectAuxiliaryIndex
              ].showpieceList[this.contextmenuGroupId].showpieceList = newArr;
              let ActiveInfo = exportActiveExhibitListInfo(
                this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
                  this.selectAuxiliaryIndex
                ].showpieceList[this.contextmenuGroupId].type,
              );
              if (ActiveInfo.type !== 'cabinet') {
                this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
                  this.selectAuxiliaryIndex
                ].showpieceList = AddXNumberExhibitList(
                  this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList[
                    this.selectAuxiliaryIndex
                  ].showpieceList,
                  this.contextmenuGroupId,
                  ActiveInfo.CoverWidth * cancatList.length,
                );
              }
            }
          }
          this.SaveFreeInfoData(2);
        } catch (err) { }
      }, 1);
    },
    async addUnitInfo(type: number) {
      let arr = {
        id: 0,
        name: '示例单元',
        description: '',
        coverUrl: '',
        parentId: 0,
        data: [],
      };
      //添加单元 type 1 添加子单元 2添加同级单元 3添加辅助信息
      let idInfo: ExportInfoType = getMOdeListcorrelation(
        this.templateMOdeList,
        this.contextmenuchildId,
        this.selectAuxiliaryIndex,
      );
      if (type === 1) {
        //添加子单元
        if (idInfo.level === 3) {
          MessagePlugin.warning('大纲最多支持三级');
          return;
        }
        arr.parentId = this.contextmenuchildId;
        let res = await moduleSave(localStorage.getItem('projectId'), arr);

        this.getFreeInfoData(res.data);
      } else if (type === 2) {
        arr.parentId = idInfo.parentId;
        let res = await moduleSave(localStorage.getItem('projectId'), arr);
        this.getFreeInfoData(res.data);
        //添加同级单元
      } else {
        //添加辅助信息
        let isAuxiliaryInfo = {
          id: 0,
          name: '示例辅助信息',
          description: '',
          coverUrl: '',
          parentId: 0,
          data: [],
          isAuxiliary: true,
        };

        isAuxiliaryInfo.parentId = this.contextmenuchildId;
        let res = await moduleSave(localStorage.getItem('projectId'), isAuxiliaryInfo);
        this.getFreeInfoData(res.data);
      }
    },
    async deleteUnitInfo() {
      //删除信息或者辅助信息
      let delId = 0;
      let idList = getMOdeListArr(this.templateMOdeList, this.contextmenuchildId);
      let idInfo: ExportInfoType = getMOdeListcorrelation(
        this.templateMOdeList,
        this.contextmenuchildId,
        this.selectAuxiliaryIndex,
      );
      if (idInfo.AuxiliaryId) {
        delId = idInfo.AuxiliaryId;
        if (idList.length === 1) {
          this.templateMOdeList[idList[0]].auxiliaryList.splice(this.selectAuxiliaryIndex, 1);
        } else if (idList.length === 2) {
          this.templateMOdeList[idList[0]].children[idList[1]].auxiliaryList.splice(this.selectAuxiliaryIndex, 1);
        } else if (idList.length === 3) {
          this.templateMOdeList[idList[0]].children[idList[1]].children[idList[2]].auxiliaryList.splice(
            this.selectAuxiliaryIndex,
            1,
          );
        }
      } else {
        delId = this.contextmenuchildId;
        if (idList.length === 1) {
          this.templateMOdeList.splice(idList[0], 1);
        } else if (idList.length === 2) {
          this.templateMOdeList[idList[0]].children.splice(idList[1], 1);
        } else {
          this.templateMOdeList[idList[0]].children[idList[1]].children.splice(idList[2], 1);
        }
      }
      let res = await moduleDelete(localStorage.getItem('projectId'), delId);
      // el.showpieceList.splice(this.contextmenuGroupId, 1);

      // this.getFreeInfoData();
    },
    //
  },
  persist: true,
});
